Skip to content

03.Using the help system

WARNING

If you aren’t willing to read PowerShell’s help files, you won’t be effective with PowerShell. You won’t learn how to use it; you won’t learn how to administer other services like Azure, AWS, Microsoft 365, and so on, with it; and you might as well stick with the GUI.

Command vs. cmdlet

PowerShell contains many types of executable commands. Some are called cmdlets (we will cover cmdlets in the next chapter), some are called functions, and so on. Col lectively, they’re all commands, and the help system works with all of them. A cmdlet is something unique to PowerShell, and many of the commands you run will be cmdlets. But we’ll try to consistently use command whenever we’re talking about the more general class of executable utility.

  • Get-Process
  • Update-Help
  • Help has a page-at-a-time display
  • Get-Help
  • Help Get-Content
  • Get-Help Get-Content
  • Get-Help Get-Content | less what is less?
  • Get-Command -Nount *event*
  • Get-Command -Verb Get
  • Get-Command *event* -Type cmdlet

Remember to use the spacebar to view the help file one page at a time and to press Ctrl-C if you want to stop viewing the file before reaching the end.

Lab

We hope this chapter has conveyed the importance of mastering the help system in PowerShell. Now it’s time to hone your skills by completing the following tasks. Keep in mind that sample answers follow. Look for italicized words in these tasks, and use them as clues to complete the tasks:

  1. Run Update-Help, and ensure that it completes without errors so that you have a copy of the help on your local computer. You need an internet connection.
  2. Can you find any cmdlets capable of converting other cmdlets’ output into HTML?
  3. Are there any cmdlets that can redirect output into a file?
  4. How many cmdlets are available for working with processes? (Hint: Remember that cmdlets all use a singular noun.)
  5. What cmdlet might you use to set to a PowerShell breakpoint? (Hint: PowerShell specific nouns are often prefixed with PS.)
  6. You’ve learned that aliases are nicknames for cmdlets. What cmdlets are avail able to create, modify, export, or import aliases?
  7. Is there a way to keep a transcript of everything you type in the shell, and save that transcript to a text file?
  8. Getting all processes can be overwhelming. How can you get processes by the name of the process?
  9. Is there a way to tell Get-Process to tell you the user who started the process?
  10. Is there a way to run a command on a remote host? (Hint: Invoke is the verb for running something now.)
  11. Examine the help file for the Out-File cmdlet. The files created by this cmdlet default to a width of how many characters? Is there a parameter that would enable you to change that width?
  12. By default, Out-File overwrites any existing file that has the same filename as what you specify. Is there a parameter that would prevent the cmdlet from over writing an existing file?
  13. How could you see a list of all aliases defined in PowerShell?
  14. Using both an alias and abbreviated parameter names, what is the shortest command line you could type to retrieve a list of commands with the word process in the name?
  15. How many cmdlets are available that can deal with generic objects? (Hint: Remember to use a singular noun like object rather than a plural one like objects.)
  16. This chapter briefly mentioned arrays. What help topic could tell you more about them?
最近更新